package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Api(tags = "文件上传")
@RestController
@RequestMapping("/admin/product")
public class FileController {

    @Autowired
    FileService fileService;

    //http://api.gmall.com/admin/product/fileUpload
    @ApiOperation("商品图片上传")
    @PostMapping("/fileUpload")
    public Result fileUpload(@RequestPart("file") MultipartFile file) throws Exception {
        log.info("图片上传。。。");
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        String url = fileService.fileUpload(file);//返回文件路径
        return Result.ok(url);
    }
}
